<?php

if(!isset($_GET['dev'])||$_GET['dev']==''){
	die('You are not allowed to access the pages');
	exit;
}

$deviceName = $_GET['dev'];

$userKey = substr(md5(time()),1,64);
$now = date('Y-m-d h:i:s',time());

$sql = 'INSERT INTO `'.GET_ACCESS_KEY_TABLE.'`(`device`,`key`,`date_time`) VALUES ("'.$deviceName.'","'.$userKey.'","'.$now.'")';
//errorEventLog::displaysSQLPhase($sql,PROGRAM_DEBUG);

$rs = $dbObj -> executeInsertStat($sql);

if($rs){
	$jsonRecord['STATUS'] = 'OK';
	$jsonRecord['DEVID'] = $rs;
	$jsonRecord['USRKEY'] = $userKey;
}else{
	$jsonRecord['STATUS'] = 'FAILED';
}

echo json_encode($jsonRecord);